/*
 * HSQLPlatformWithNativeSequence.java
 *
 * Created on 26 de Junho de 2007, 14:45
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package br.unifor.finance.persistence.dao.jpa.hsqldb;

import java.io.IOException;
import java.io.Writer;
import oracle.toplink.essentials.exceptions.ValidationException;
import oracle.toplink.essentials.internal.sessions.AbstractSession;
import oracle.toplink.essentials.platform.database.HSQLPlatform;
import oracle.toplink.essentials.queryframework.ValueReadQuery;
import oracle.toplink.essentials.sequencing.Sequence;

/**
 *
 * @author Cleilson
 */
public class HSQLPlatformWithNativeSequence extends HSQLPlatform {
  
  /**
   * Creates a new instance of HSQLPlatformWithNativeSequence
   */
  public HSQLPlatformWithNativeSequence() {
    super();
  }
  
  public boolean supportsNativeSequenceNumbers() {
    return true;
  }

  public boolean supportsUniqueKeyConstraints() {
    return true;
  }
  
  public boolean shouldNativeSequenceAcquireValueAfterInsert() {
    return true;
  }

  public ValueReadQuery buildSelectQueryForNativeSequence() {
    return new ValueReadQuery("CALL IDENTITY()");
  }

  public void printFieldIdentityClause(Writer writer) throws ValidationException {
    try {
      //writer.write(" IDENTITY");
      writer.write(" GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1)");
    } catch (IOException e) {
      throw ValidationException.fileError(e);
    }
  }

  public void printFieldUnique(Writer writer, boolean isUnique, AbstractSession session, String qualifiedFieldName) throws IOException {
    super.printFieldUnique(writer, isUnique, session, qualifiedFieldName);
  }
  
}
